package com.zr.service.impl;

import java.util.ArrayList;

import com.zr.dao.ContentDao;
import com.zr.dao.impl.ContentDaoImpl;
import com.zr.model.Content;
import com.zr.model.CurrentContent;
import com.zr.model.Type;
import com.zr.service.ContentService;

import net.sf.json.JSONObject;

/**
 * 具体实现类
 * @author lf
 *
 */
public class ContentServiceImpl implements ContentService{

	ContentDao cd = new ContentDaoImpl();
	
	@Override
	public JSONObject getAllCurrent() {
		ArrayList<CurrentContent> list = cd.getAllContent();
		int total = cd.getAllCount();
		JSONObject json = new JSONObject();
		json.put("total", total);
		json.put("rows", list);
		return json;
	}

	@Override
	public JSONObject getCurrentContentByLimit(int page, int pageSize) {
		ArrayList<CurrentContent> list = cd.getContentByLimmit(page, pageSize);
		JSONObject json = new JSONObject();
		int total = cd.getAllCount();
		json.put("total",total);
		json.put("rows", list);
		return json;
	}

	@Override
	public JSONObject getContentBySearch(String title, String center, String startDate, String endDate,
			String state,int page,int pageSize) {
		JSONObject json = new JSONObject();
		ArrayList<CurrentContent> list = cd.getContentByAll(title, center, startDate, endDate, state, page, pageSize);
		int total = cd.getCountByAll(title, center, startDate, endDate, state);
		json.put("total", total);
		json.put("rows", list);
		return json;
	}

	@Override
	public JSONObject getContentByCname(String cname, int page, int pageSize) {
		ArrayList<CurrentContent> list = new ArrayList<>();
		list = cd.getContentByCname(cname, page, pageSize);
		int total = cd.getCountByCname(cname);//cname的总记录数
		JSONObject json = new JSONObject();
		json.put("total", total);
		json.put("rows", list);
		return json;
	}

	@Override
	public Content getContentByCid(int cid) {
		Content content = cd.getContentByCid(cid);
		return content;
	}
	
	@Override
	public ArrayList<Content> getRelevantContentByCname(String cname,int cid) {
		ArrayList<Content> list = cd.getRelevantContentByCname(cname,cid);
		return list;
	}

	@Override
	public ArrayList<Type> getMaxNumberContent() {
		ArrayList<Type> list = cd.getMaxNumberContent();
		return list;
	}

	@Override
	public void addContent(String title, String abstract1, String type, String file, String special) {
		// TODO Auto-generated method stub
		cd.addContent(title, abstract1, type, file, special);
	}
	
	@Override
	public String getData() {
		StringBuffer sb = new StringBuffer();
		sb.append(cd.getCount("政策法规"));
		sb.append(",");
		sb.append(cd.getCount("环保标准"));
		sb.append(",");
		sb.append(cd.getCount("环保业务"));
		sb.append(",");
		sb.append(cd.getCount("环保培训"));
		return sb.toString();
	}

	@Override
	public void deleteConten(int[] cid) {
		// TODO Auto-generated method stub
		cd.deleteContent(cid);
	}

	@Override
	public boolean updateContentStateByCid(int cid) {
		return cd.deleteContentByCid(cid);
	}


}
